﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Dao.Intermediarios
{
    public class IPOrdenProduccion:Intermediario
    {
           public override void save<T>(T entity)
        {
            try 
	        {
                OrdenProduccion op = entity as OrdenProduccion;
                dao.OrdenProduccions.InsertOnSubmit(op);
               
	        }
	        catch (Exception)
	        {		
		        throw;
	        }
        }

        public override List<T> getAll<T>()
        {
            return (from op in dao.OrdenProduccions select op).ToList() as List<T>;
        }

        public override List<T> getByCriterio<T>(string att, string op, string val)
        {
            throw new NotImplementedException();
        }

        public override IList<T> getCriterioById<T>(string att, string op, int val)
        {
            return (from oprod in dao.OrdenProduccions where oprod.idOP== Convert.ToInt16(val) select oprod).ToList() as List<T>;
        }

        public  IList<T> getPorNroOrden<T>(string att, string op, int val)
        {
            return (from oprod in dao.OrdenProduccions where oprod.nroOP == Convert.ToInt16(val) select oprod).ToList() as List<T>;
        }

        public override object getPorId(int id)
        {
            //IMPLEMENTAR ESTE PARA BUSCAR POR NRO DE ORDEN DE PRODUCION
            throw new NotImplementedException();
        }

        public override IList<T> getPorCriterio<T>(string name)
        {
            throw new NotImplementedException();
        }

        public override void Update<T>(T entity)
        {
            try
            {

            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public override void Delete(int id)
        {
            try
            {
                var ct = (from op in dao.OrdenProduccions where op.nroOP == id select op).SingleOrDefault();

                if (ct != null)
                {
                  //  ct.Activo = false;
                    dao.OrdenProduccions.DeleteOnSubmit(ct);
                    dao.SubmitChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
      }
    }

